package agngui.ui;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextPane;

/**
 * A Help Window that will display text and messages that are supposed to help
 * the user to navigate around the UI and explain how to use its features.
 * 
 * @author Ben Bloom
 *
 */
public class HelpWindow {
	
	/**
	 * the text that is actually displayed in the scrolling text area
	 */
	private static String[] help_text = new String[] {
		"Helpful text is supposed to go here.",
		"This is just a stub implementation for now.",
	};

	/**
	 * the operating system's end of line character
	 */
	private static String endl = System.getProperty("line.separator");
	
	/**
	 * the singleton instance of the help window
	 */
	private static HelpWindow instance = new HelpWindow();
	
	/**
	 * shows the help window
	 */
	public static void show() {
		instance.window.setVisible(true);
	}
	
	/**
	 * the frame that contains all of the window's information
	 */
	private JFrame window;
	
	/**
	 * the text pane that displays all of the information
	 */
	private JEditorPane text_pane;
	
	/**
	 * private constructor, creates an instance of the help window
	 */
	private HelpWindow() {
		window = new JFrame("Help");
		window.setLocationByPlatform(true);
		window.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		
		window.setSize(800, 600);
		Container cpane = window.getContentPane();
		cpane.setLayout(new BorderLayout());
		
		try {
			URL url = new URL("jar:file:AGNGUI.jar!/bin/manual/manual.html");
			text_pane = new JEditorPane(url);
		} catch(IOException ioe) {
			ioe.printStackTrace(System.err);
		}
		
		text_pane.setEditable(false);
		JScrollPane scroller = new JScrollPane(text_pane);
		cpane.add(scroller, BorderLayout.CENTER);
		
		JMenuBar menu_bar = new JMenuBar();
		JMenu file_menu = new JMenu("File");
		file_menu.getPopupMenu().setLightWeightPopupEnabled(false);
		file_menu.setMnemonic(KeyEvent.VK_F);
		JMenuItem close_item = new JMenuItem("Close");
		close_item.setMnemonic(KeyEvent.VK_C);
		close_item.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				window.setVisible(false);
			}
		});
		file_menu.add(close_item);
		menu_bar.add(file_menu);
		window.setJMenuBar(menu_bar);
	}
}
